/**
 * https://codeforces.com/contest/416/problem/C
 * 416C.预订系统
 * 欧琳琳 2024.10.10
 * 二分查找 贪心算法
 */

#include<bits/stdc++.h>
using namespace std;
 
struct Request
{
    int cnt;
    int payment;
    int index;
};
 
struct Table
{
    int capacity;
    int index;
};
 
int main()
{
    int n;
    cin >> n;
    vector<Request>request(n);
    for(int i=0;i<n;i++)
    {
        cin >> request[i].cnt >> request[i].payment;
        request[i].index=i+1;
    }
    int k;
    cin >> k;
    vector<Table>table(k);
    for(int i=0;i<k;i++)
    {
        cin >> table[i].capacity;
        table[i].index=i+1;
    }
    sort(request.begin(),request.end(),[](const Request &a,const Request &b){return a.payment>b.payment;});
    sort(table.begin(),table.end(),[](const Table &a,const Table &b){return a.capacity<b.capacity;});
    vector<bool>table_used(k,false);
    vector<pair<int,int>>accepted;
    int total=0;
    for(const auto &req:request)
    {
        for(int i=0;i<k;i++)
        {
            if(!table_used[i]&&table[i].capacity>=req.cnt)
            {
                table_used[i]=true;
                total+=req.payment;
                accepted.push_back({req.index,table[i].index});
                break;
            }
        }
    }
    cout << accepted.size() << " " << total << endl;
    for(const auto &pair:accepted)
    {
        cout << pair.first << " " << pair.second << endl;
    }
    return 0;
}